package cn.microven.mindmap.oprations;

import cn.microven.mindmap.components.node.AbstractMapNode;
import cn.microven.mindmap.struture.MindMap;

public class ChangeNodeRadius implements Operation {

    private double oldRadius;

    private double newRadius;

    private AbstractMapNode node;

    public ChangeNodeRadius(double oldColor, double newColor, AbstractMapNode node) {
        this.oldRadius = oldColor;
        this.newRadius = newColor;
        this.node = node;
    }

    @Override
    public void start(boolean isRedo) {
        node.setRadius(newRadius);

        if (!isRedo) {
            if (MindMap.getLastOperation() != null) {
                if (MindMap.getLastOperation().getClass() == this.getClass()) {
                    ChangeNodeRadius old = (ChangeNodeRadius) MindMap.getLastOperation();
                    this.oldRadius = old.getOldRadius();
                    MindMap.getInstance().getOperations().remove(old);
                    MindMap.getInstance().setOprIndex(MindMap.getInstance().getOprIndex()-1);
                }
            }
            MindMap.addOperation(this);
        }
    }

    @Override
    public void undo() {
        node.setRadius(oldRadius);
    }

    public double getOldRadius() {
        return oldRadius;
    }

    public void setOldRadius(double oldRadius) {
        this.oldRadius = oldRadius;
    }

    public double getNewRadius() {
        return newRadius;
    }

    public void setNewRadius(double newRadius) {
        this.newRadius = newRadius;
    }

    public AbstractMapNode getNode() {
        return node;
    }

    public void setNode(AbstractMapNode node) {
        this.node = node;
    }
}
